local gebo = fk.CreateSkill {
  name = "tyj_heg__gebo",
}

local U = require "packages.utility.utility"

Fk:loadTranslationTable {
  ['tyj_heg__zonghengdiq'] = "当拥有“纵横”效果的技能发动结算完成后，可以令技能目标角色获得对应修订描述后的技能，直到其下回合结束。",
  ['tyj_heg__zhgebodic'] = "出牌阶段限一次，你可以与一名角色拼点，赢的角色可以令两名拼点牌为【杀】的角色回复1点体力。",
  ["tyj_heg__gebo"] = "戈帛",
  [":tyj_heg__gebo"] = "出牌阶段限一次，你可以与两名角色拼点，赢的角色可以令其他拼点牌为【杀】的角色回复1点体力。"..
  "<a href='heg__zongheng'><b>纵横<b></a>：将〖戈帛〗描述中的“两”改为“一”。",
  ["tyj_heg__qiansong"] = "谦颂",
  [":tyj_heg__qiansong"] = "一名角色回满体力后，你可以令当前回合角色摸一张牌，然后你可以与其交换装备区内的一张牌。",
  ["#tyj_heg__qiansong-prompt"] = "是否对 %dest 发动 谦颂 令其摸一张牌？",
  ["#tyj_heg__qiansong-swap"] = "谦颂：是否与 %dest 交换装备区内的一张牌（选择其装备区内一张牌交换）？",

  ["@@tyj_heg__gebo_manoeuvre"] = "戈帛 纵横",
  ["$tyj_heg__gebo1"] = "握手言和，永罢刀兵。",
  ["$tyj_heg__gebo2"] = "重归于好，摒弃前仇。",
}

gebo:addEffect("active", {
  anim_type = "support",
  card_num = 0,
  min_target_num = 2,
  max_target_num = 2,
  prompt = "戈帛：与两名角色共同拼点。",
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(gebo.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected < 2 and to_select ~= player and player:canPindian(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:sortByAction(effect.tos)
    local pd = U.jointPindian(player, effect.tos, gebo.name)
    if pd.winner and pd.winner:isAlive() then
      local recover = {}
      local cid = pd.fromCard:getEffectiveId()
      if cid and Fk:getCardById(cid).trueName == "slash" then
        table.insert(recover, pd.from)
      end
      for _, pid in ipairs(effect.tos) do
        if pd.results[pid] and pd.results[pid].toCard then
          if pd.results[pid].toCard and pd.results[pid].toCard.trueName == 'slash' then
            table.insert(recover, pid)
          end
        end
      end
      if table.contains(recover, pd.winner) then
        table.removeOne(recover, pd.winner)
      end
      if #recover > 1 then
        local to = room:askToChoosePlayers(pd.winner, {
        targets = recover,
        min_num = 2,
        max_num = 2,
        prompt = "戈帛：是否令两名拼点牌为【杀】的角色各回复1点体力？？",
        skill_name = gebo.name,
        cancelable = true,
      })
    if #to>0 then
      room:sortByAction(to)
      for _, p in ipairs(to) do
            if p:isAlive() then
              room:recover { num = 1, skillName = gebo.name, who = p, recoverBy = pd.winner }
            end
          end
    end
      end
    end
    local choices = { "令与你拼点的角色获得〖戈帛（纵横）〗直到其下回合结束", "Cancel" }
    if room:askToChoice(player, {
          choices = choices,
          skill_name = gebo.name,
        }) ~= "Cancel" then
      for _, p in ipairs(effect.tos) do
        if p:isAlive() then
          room:setPlayerMark(p, "@@tyj_heg__gebo_manoeuvre", 1)
          room:handleAddLoseSkills(p, "tyj_heg__gebo_manoeuvre", nil)
        end
      end
    end
  end,
})
gebo:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("tyj_heg__gebo_manoeuvre", true, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "-tyj_heg__gebo_manoeuvre", nil)
    room:setPlayerMark(player, "@@tyj_heg__gebo_manoeuvre", 0)
  end,
})
return gebo
